<?php
/**
 * Created by PhpStorm.
 * User: linyh
 * Date: 2017/11/25 0025 10:13
 */
?>
<link href="/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet" />

<section class="content-header">
    <h1>
        添加成员
        <!--<small>Preview</small> -->
    </h1>
    <!-- <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Tables</a></li>
        <li class="active">Data tables</li>
    </ol> -->
</section>

<!-- Main content -->
<section class="content">
<div class="row">
    <div class="col-md-12">
        <!-- general form elements -->
        <div class="box box-default">
            <!-- /.box-header -->
            <!-- form start -->
            <form id="form" role="form" class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label for="exampleInputEmail1" class="col-sm-5 control-label">成员姓名</label>
                        <div class="col-sm-4">
                        <input id="exampleInputEmail1" class="form-control" type="text" name="name" placeholder="请输入成员姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input2" class="col-sm-5 control-label">公司职位</label>
                        <div class="col-sm-4">
                        <select id="input2" class="form-control" name="position">
                            <option value="1">首席执行官</option>
                            <option value="2">设计总监</option>
                            <option value="3">营销总监</option>
                            <option value="4">生产总监</option>
                        </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input3" class="col-sm-5 control-label">每财年工资</label>
                        <div class="col-sm-4">
                        <input id="input3" class="form-control" type="text" value="10000" disabled>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->

                <div class="box-footer text-center">
                    <button type="submit" class="btn btn-success">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
</section>

<script>
$('#input2').change(function() {
    var salarys = {
        '1':10000,
        '2':8000,
        '3':8000,
        '4':8000,
    }
    $('#input3').val(salarys[$('#input2').val()])
})
$(function() {
    if(global.user.role==2) {
        $('#input2').find('[value=2]').remove();
        $('#input2').find('[value=4]').remove();
    } else if(global.user.role==3) {
        $('#input2').find('[value=1]').text('政府官员');
        $('#input2').find('[value=2]').remove();
        $('#input2').find('[value=3]').remove();
        $('#input2').find('[value=4]').remove();
    } else {

    }
})
$('#form').submit(function(e) {
    e.preventDefault();
    var str = $('#form').serialize();
    console.log(str);

    $.ajax('/api/member/create', {
        type: 'POST',
        data: str,
        dataType: 'json',
        headers: {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
    }).then(function(ret) {
        if(ret.state ==0) {
            alert('保存成功');
            location.href = '/member/index';
        } else {
            alert(ret.message);
        }
    });
});

</script>